<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>回掉函数</title>
    <style>
        #box1 {
            position: relative;
        }
    </style>
</head>
<body>
    <div id="box1">First Box</div>
    <script>
        function animateIt(elementId) {
            var elem = document.getElementById(elementId);
            var tick = 0;
            var timer = setInterval(function() {
                if(tick < 100) {
                    elem.style.left = elem.style.top = tick + 'px';
                    tick ++ ;
                }else {
                    clearInterval(timer);
                    console.log(tick === 100 + 'Tick accessed via a closure.');
                }
            }, 10)
        }
        animateIt("box1")
    </script>
</body>
</html>